package com.blue.waffle.iwc.ui;

import com.badlogic.gdx.scenes.scene2d.EventListener;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.blue.waffle.iwc.game.IWCGame;

public class MessageDialog extends Dialog {

	private String message;
	//private Cell messageCell;
	private int buttons;
	public static final int BTN_OK=2;
	public static final int BTN_CANCEL=4;
	public static final int BTN_YES=8;
	public static final int BTN_NO=16;
	public static final int BTN_YES_NO=BTN_YES|BTN_NO;
	public static final int BTN_OK_CANCEL=BTN_OK|BTN_CANCEL;
	private EventListener actorListener;
	private Skin skin;
	/**
	 * @param title
	 * @param skin
	 */
	public MessageDialog(String message,String title, Skin skin,int buttons) {
		this(message, title, skin, buttons, new ClickListener());
	}
	
	public MessageDialog(String message,String title, Skin skin){
		this(message,title, skin,BTN_OK);
	}
	
	public MessageDialog(String title, Skin skin) {
		this("",title, skin);
		/*this.message="";
		this.buttons=BTN_OK;
		setupDialog();
		hide();*/
	}
	
	public MessageDialog(String message,String title, Skin skin,int buttons,EventListener buttonActorListener) {
		super(title, skin);
		this.skin=skin;
		this.message=message;
		this.buttons=buttons;
		this.actorListener=buttonActorListener;
		setupDialog();
		//hide();
	}
	
	
	private void setupDialog(){
		setModal(true);
		setMovable(false);
		//text(message); 
		
		Label messageLabel=new Label(message, skin);
		messageLabel.setWrap(true);
		ScrollPane scrollPane=new ScrollPane(messageLabel, skin);
		scrollPane.size(IWCGame.VIRTUAL_WIDTH/2, IWCGame.VIRTUAL_HEIGHT/2);
		getContentTable().row().pad(20);
		getContentTable().add(scrollPane).width(IWCGame.VIRTUAL_WIDTH/2).height(IWCGame.VIRTUAL_HEIGHT/2);
		getContentTable().row();
		switch (buttons) {
		case BTN_OK:
			button("OK",BTN_OK).addListener(actorListener);
			break;
		case BTN_CANCEL:
			button("Cancel",BTN_CANCEL).addListener(actorListener);
			break;
		case BTN_OK_CANCEL:
			button("OK",BTN_OK).addListener(actorListener);
			button("Cancel",BTN_CANCEL).addListener(actorListener);
			break;
		case BTN_YES:
			button("Yes",BTN_YES).addListener(actorListener);
			break;
		case BTN_NO:
			button("No",BTN_NO).addListener(actorListener);
			break;
		case BTN_YES_NO:
			button("Yes",BTN_YES).addListener(actorListener);
			button("No",BTN_NO).addListener(actorListener);
			break;
		default:
			break;
		}
		//setSize(200, 300);
	}
	

}
